import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  // {
  //   name: 'notFound',
  //   path: '/:path(.*)+',
  //   redirect: {
  //     name: 'goods'
  //   }
  // },
  {
    name: 'home',
    path: '/',
    component: () => import('@/view/home/index.vue'),
    meta: {
      title: '首页'
    }
  },
  {
    name: 'user',
    path: '/user',
    component: () => import('@/view/user/index.vue'),
    meta: {
      title: '个人中心'
    }
  },
  {
    name: 'mycourse',
    path: '/mycourse',
    component: () => import('@/view/myCourse/index.vue'),
    meta: {
      title: '我的课程'
    }
  },
  {
    name: 'mycertificate',
    path: '/mycertificate',
    component: () => import('@/view/myCertificate/index.vue'),
    meta: {
      title: '我的课程'
    }
  },
  {
    name: 'myfeedback',
    path: '/myfeedback',
    component: () => import('@/view/myFeedback/index.vue'),
    meta: {
      title: '课程反馈'
    }
  },
  {
    name: 'evaluatecourse',
    path: '/evaluatecourse',
    component: () => import('@/view/evaluateCourse/index.vue'),
    meta: {
      title: '评价课程'
    }
  },
  {
    name: 'login',
    path: '/login',
    component: () => import('@/view/base/login.vue'),
    meta: {
      title: '登录'
    }
  },
  {
    name: 'cart',
    path: '/cart',
    component: () => import('@/view/cart/index.vue'),
    meta: {
      title: '购物车'
    }
  },
  {
    name: 'goods',
    path: '/goods',
    component: () => import('@/view/goods/index.vue'),
    meta: {
      title: '商品详情'
    }
  },

  
]

const router = createRouter({
  routes,
  history: createWebHistory()
})
 

router.beforeEach((to, from, next) => {
  const title = to?.meta?.title
  if (title) {
    document.title = title as string
  }
  
 
  next()
  
})

export default router
